<?php

/**
 * @author SNAKER
 * @copyright 2012
 */
error_reporting(E_ERROR | E_WARNING | E_PARSE);
if(isset($_GET["ip"]))
{

    $isContinue = true;
    
    function getSideSitesData($ip, $page)
    {
        global $isContinue;
        $matches = array();
        $url = "http://cn.bing.com/search?q=ip:".$ip."&first=".(50*($page-1)+1)."&count=50";
        $contents = file_get_contents($url);
        $getcontents = iconv("utf-8", "gbk//IGNORE",$contents);  
        if(preg_match_all("/<h3>.*?href=\"http:\/\/(.*?)\/.*?\".*?>(.*?)<\/a>.*?<\/h3>/i", $getcontents, $matches))
        {        
            //print_r($matches[1]);
        }
        else
        {
            $isContinue = false;
        }
        return $matches;
    }
    
    $arrSideSites = array(); 
    $ip = $_GET["ip"];
    //$ip = "101.226.4.21";
    for($page=1; $page < 6; $page++)
    {
        if($isContinue)
        {
           $tempArray = getSideSitesData($ip, $page);
           foreach($tempArray[1] as $key => $value)
           {
                if(!array_key_exists($value, $arrSideSites))
                {
                    $arrSideSites[$value] = $tempArray[2][$key];
                }
           }
        }
    }
    $count = 0;
    foreach($arrSideSites as $key => $value)
    {
        $count++;
        echo "<a href=http://$key/><p>".$value."</p></a>";
        //echo " $count  <a href=http://$key/><p>".$value."</p></a>   ";
        //echo "<a href=http://$key/>".$key."  ==>>  ".$value."</a><br />";
    }
}

?>